package com.taotao.controller;

import org.apache.taglibs.standard.lang.jstl.test.beans.PublicInterface2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.taotao.comm.pojo.EasyUIDataGridResult;
import com.taotao.pojo.TbItem;
import com.taotao.pojo.TbItemDesc;
import com.taotao.service.ItemService;
import com.taotao.utils.IDUtils;
import com.taotao.utils.TaotaoResult;

@Controller
public class ItemController {
	@Autowired
	private ItemService itemService;
	
	
	@RequestMapping("/rest/item/update")
	@ResponseBody
	public TaotaoResult editItem(TbItem item,String desc){
		TaotaoResult result = itemService.editTBitem(item, desc);
		
		return result;
	}
	

	
	@RequestMapping("/item/save")
	@ResponseBody
	public TaotaoResult saveItem(TbItem item,String desc){
		TaotaoResult result = itemService.saveTbItem(item, desc);
		
		return result;
	}
	
	@RequestMapping("/item/list")
	@ResponseBody
	public EasyUIDataGridResult itemList(Integer page,Integer rows){
		EasyUIDataGridResult result = itemService.getTbItems(page, rows);
		return result;
	}
	
	//根据商品id删除
		//商品状态，1-正常，2-下架，3-删除
	@RequestMapping("/rest/item/delete")
	@ResponseBody
	public TaotaoResult deleteItem(String ids){
		TaotaoResult result = null;
		try {
			TbItem item = new TbItem();
			item.setStatus((byte)3);
			result = itemService.changeStatus(item, ids);
			result.setStatus(200);
			return result;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	
	
	
	//根据商品id下架
	//商品状态，1-正常，2-下架，3-删除
	@RequestMapping("/rest/item/instock")
	@ResponseBody
	public TaotaoResult instock(String ids){
		TaotaoResult result = null;
		try {
			TbItem item = new TbItem();
			item.setStatus((byte)2);
			result = itemService.changeStatus(item, ids);
			result.setStatus(200);
			return result;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}
	//根据商品id上架
		//商品状态，1-正常，2-下架，3-删除
		@RequestMapping("/rest/item/reshelf")
		@ResponseBody
		public TaotaoResult reshelf(String ids){
			TaotaoResult result = null;
			try {
				TbItem item = new TbItem();
				item.setStatus((byte)1);
				result = itemService.changeStatus(item, ids);
				result.setStatus(200);
				return result;
			} catch (Exception e) {
				e.printStackTrace();
			}
			return result;
		}
	
	
	
	
	
}